package com.company.笔试.二叉搜索树的第k个节点;/*
public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}
左根右
*/
import com.company.笔试.TreeNode;

import java.util.*;
public class Solution {
    public int n;
    public int status= 0;
    public TreeNode res = null;
    TreeNode KthNode(TreeNode pRoot, int k) {
        if(pRoot==null||k==0) return null;
        n=k;
        midFind(pRoot);
        //双指针
        if(status==1) return res;
        return null;
        
    }
    public void midFind(TreeNode pRoot) {
        
        if(pRoot.left!=null) midFind(pRoot.left);
        n--;
        if(n==0){
            
            res = pRoot;
            status = 1;
            
            return;
        }
        
        if(pRoot.right!=null)midFind(pRoot.right);
    }

}